|
|
|
|
|
|
|
Understanding How to Model and Design for Classes and Subsystems |
|
|
|
|
|
|
|
|
You completed your initial set of interaction and class diagrams, started coding, and everything seemed to be smooth sailing. Then you ran into design flaws in some class interfaces that you did not anticipate while you were in the elaboration phase. What to do? Quite simply, you need to revisit those diagrams and pinpoint applicationwide ramifications of those flaws. |
|
|
|
|
|
|
|
|
Designing and Modeling Classes |
|
|
|
|
|
|
|
|
Although formal design might end as construction begins, you will still make some micro-level design decisions. For example, you have to refine a particular aggregation association between classes into either composition or containment. Aggregation represents a tightly or loosely coupled ownership relationship between an aggregate object and the objects it's aggregating. Ownership means that the aggregate object owns either the lifetime of an object (composition) or the exclusive use of services (containment) of an object. Aggregation is best defined by the distinction between composition and containment. |
|
|
|
|
|
|
|
|
The composite object is responsible for creating and destroying the object of which it is composed. In some cases, the composite object specifies that another object be delegated such responsibility, as in the case of object factories and garbage collectors. In such cases, a factory must be tasked only with creating the object, and the garbage collector must be responsible only for destroying the object. If a factory or garbage collector uses these objects for any other reason, it could be argued that the factory and the garbage collector contain the object rather than create or destroy it. |
|
|
|
|
|
|
|
|
Containment is similar to composition, except that the containing object is not responsible for the life of the contained object. An object can create another object for its exclusive use but can't pass the object to another for the other's use. This is the case with collections in which a containing object creates an object, populates it with data from a graphical user interface, and then passes that object to a collection. A collection object contains objects. |
|
|
|
|
|
|
|
|
New Term: Aggregation is the tightly or loosely coupled ownership relationship between an aggregate object and the objects it's aggregating. Composition is the lifetime ownership of an object by an aggregate object. Containment is ownership of the exclusive use of an object by an aggregate object. |
|
|
|
|
|